package cn.mesmile.juc.dead;

/**
 * @author zb
 * @date 2021/11/14 16:32
 * @Description
 */
public class SingleInstance {

    /**
     * volatile 禁止指令重拍
     * 有可能能在创建对象的时候，还没有给新对象赋值，就被拿去用了
     */
    private static volatile SingleInstance instance;

    private SingleInstance(){}

    public static synchronized SingleInstance getInstance(){
        if (instance == null){
            synchronized (SingleInstance.class){
                if (instance == null){
                    instance = new SingleInstance();
                }
            }
        }
        return instance;
    }

}
